import 'package:syria_sports/data/models/error_model.dart';

import '../../core/utils/pref_utils.dart';
import '../../core/utils/show_toast.dart';
import '../../presentation/gyms/gyms_page/models/gym.dart';
import '../apiClient/api_client.dart';
import '../apiClient/api_keys.dart';
import '../models/data.dart';
import '../remote/dio_helper.dart';

class AdditionalOperationsController {
  static Future<Data?> getUIAndDataFrom(String from) async {
    var res =
        await DioHelper.getData(url: from, bearerToken: PrefUtils.getToken());

    if (res.statusCode != 200) {
      ErrorModel.fromResponse(res);
      return null;
    } else {
      // showMessage(res.data[ApiKeys.message]);
    }
    Data response = Data.fromJson(res.data);
    return response;
  }

  static Future<void> getData(String from) async {
    var res =
        await DioHelper.getData(url: from, bearerToken: PrefUtils.getToken());
    if (res.statusCode != 200) {
      ErrorModel.fromResponse(res);
    }
    return;
  }

  static Future<void> postData(
      {required String from, required Map<String, dynamic> data}) async {
    var res = await DioHelper.postData(
      url: from,
      data: data,
      bearerToken: PrefUtils.getToken(),
    );
    if (res == null) return;
    if (res.statusCode != 200) {
      ErrorModel.fromResponse(res);
    }else{
      if(res.data != null && res.data["message"]!= null && res.data["message"] is String) {
        showMessage(res.data["message"]);
      }
    }
    return;
  }
}
